Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flake8-quotes] Fix Autofix Error (Q000, Q002) #10199

Merged
merged 14 commits into from
Mar 18, 2024

Conversation

robincaloudis
Copy link
Contributor

@robincaloudis robincaloudis commented Mar 2, 2024

Summary

In issue #6785 it is reported that a docstring in the form of ''"assert" ' SAM macro definitions ''' is autocorrected to """assert" ' SAM macro definitions ''' (note the triple quotes one only one side), which breaks the python program due undetermined string lateral.

  • Q002: Not only would docstrings in the form of ''"assert" ' SAM macro definitions ''' (single quotes) be autofixed wrongly, but also e.g. ""'assert' ' SAM macro definitions ''' (double quotes). The bug is present for docstrings in all scopes (e.g. module docstrings, class docstrings, function docstrings)

  • Q000: The autofix error is not only present for Q002 (docstrings), but also for inline strings (Q000). Therefore s = ''"assert" ' SAM macro definitions ''' will also be wrongly autofixed.

Note that situation in which the first string is non-empty can be fixed, e.g. '123'"assert" ' SAM macro definitions ''' -> "123""assert" ' SAM macro definitions ''' is valid.

What

  • Change FixAvailability of Q000 Q002 to Sometimes
  • Changed both rules such that docstrings/inline strings that cannot be fixed are still reported as bad quotes via diagnostics, but no fix is provided

Test Plan

  • For Q000: Add docstrings in different scopes that (partially) would have been autofixed wrongly
  • For Q002: Add inline strings that (partially) would have been autofixed wrongly

Closes #6785

Copy link
Contributor

github-actions bot commented Mar 2, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1 -37 violations, +0 -0 fixes in 1 projects; 42 projects unchanged)

pandas-dev/pandas (+1 -37 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- pandas/io/stata.py:1085:9: PLR0917 Too many positional arguments (11/5)
- pandas/io/stata.py:1236:40: PLR6201 Use a `set` literal when testing for membership
- pandas/io/stata.py:1395:40: PLR6201 Use a `set` literal when testing for membership
- pandas/io/stata.py:1615:9: PLR0914 Too many local variables (20/15)
- pandas/io/stata.py:1615:9: PLR0917 Too many positional arguments (8/5)
- pandas/io/stata.py:1720:29: PLR6201 Use a `set` literal when testing for membership
- pandas/io/stata.py:1742:29: PLR6201 Use a `set` literal when testing for membership
- pandas/io/stata.py:1745:31: PLR6201 Use a `set` literal when testing for membership
- pandas/io/stata.py:1791:33: PLR6201 Use a `set` literal when testing for membership
- pandas/io/stata.py:2058:30: PLR6201 Use a `set` literal when testing for membership
- pandas/io/stata.py:2060:32: PLR6201 Use a `set` literal when testing for membership
... 18 additional changes omitted for rule PLR6201
- pandas/io/stata.py:2281:9: PLR0917 Too many positional arguments (10/5)
- pandas/io/stata.py:2426:9: PLR6301 Method `_validate_variable_name` could be a function, class method, or static method
- pandas/io/stata.py:2448:17: PLR0916 Too many Boolean expressions (7 > 5)
- pandas/io/stata.py:2866:9: PLR6301 Method `_convert_strls` could be a function, class method, or static method
- pandas/io/stata.py:3244:9: PLR0917 Too many positional arguments (11/5)
- pandas/io/stata.py:3637:9: PLR0917 Too many positional arguments (12/5)
- pandas/io/stata.py:3681:9: PLR6301 Method `_validate_variable_name` could be a function, class method, or static method
- pandas/io/stata.py:3704:17: PLR0916 Too many Boolean expressions (10 > 5)
- pandas/io/stata.py:787:7: PLW1641 Object does not implement `__hash__` method
+ pandas/io/stata.py:864:16: E999 SyntaxError: Unexpected token Newline

Changes by rule (7 rules affected)

code total + violation - violation + fix - fix
PLR6201 25 0 25 0 0
PLR0917 5 0 5 0 0
PLR6301 3 0 3 0 0
PLR0916 2 0 2 0 0
E999 1 1 0 0 0
PLR0914 1 0 1 0 0
PLW1641 1 0 1 0 0

Copy link

codspeed-hq bot commented Mar 3, 2024

CodSpeed Performance Report

Merging #10199 will not alter performance

Comparing robincaloudis:rc-fix-q000-and-q002 (f4da30c) with main (fd26b29)

Summary

✅ 30 untouched benchmarks

@robincaloudis
Copy link
Contributor Author

@charliermarsh, do you mind to review this fix? Thanks!

@robincaloudis robincaloudis changed the title WIP: [flake8-quotes] Fix Autofix Error (Q000, Q002) [flake8-quotes] Fix Autofix Error (Q000, Q002) Mar 17, 2024
@zanieb zanieb self-assigned this Mar 17, 2024
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks! Appreciate all the additional tests. Sorry it took me so long to get to it.

@charliermarsh charliermarsh enabled auto-merge (squash) March 18, 2024 01:13
@charliermarsh charliermarsh merged commit 2edd617 into astral-sh:main Mar 18, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rules Q002,PTH116 causes autofix error
3 participants